package com.example.administrator.waitan.find;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.waitan.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/1/15.
 */
public class FindViewPagerAdapter extends PagerAdapter {
    private Context context;
    private ArrayList<View> views;

    public FindViewPagerAdapter(Context context) {
        this.context = context;
        addData();
    }

    public void addData( ){
        View v = LayoutInflater.from(context).inflate(R.layout.viewpager_homepager,null);
        View v1 = LayoutInflater.from(context).inflate(R.layout.viewpager_homepager_two,null);
        View v2 = LayoutInflater.from(context).inflate(R.layout.viewpager_homepager_three,null);
        views = new ArrayList<>();
        views.add(v);
        views.add(v1);
        views.add(v2);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return views.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = views.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = views.get(position);
        container.removeView(view);

    }
}
